package com.novel.authorization.staff.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.novel.authorization.staff.entity.NfUser;
import com.novel.authorization.staff.service.NfUserService;
import com.novel.authorization.staff.vo.UserInfoVO;
import com.novel.base.entity.LayUIPage;
import com.novel.base.entity.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户控制器
 *
 * @author 樊温军
 * @date 2025/3/18 上午10:32
 */
@Slf4j
@RestController
@RequestMapping("/user")
@Api(tags = "用户控制器")
@RequiredArgsConstructor
public class NfUserController {

    private final NfUserService nfUserService;

    /**
     * 用户列表—分页
     *
     * @return LayUIPage < SysRole>
     */
    @SaCheckPermission("nfUser:page")
    @GetMapping("/page")
    @ApiOperation(value = "用户列表—分页")
    public LayUIPage<NfUser> getPage(Page<NfUser> page, NfUser sysUser) {
        try {
            IPage<NfUser> iPage = nfUserService.getPage(page, sysUser);
            return LayUIPage.ok(iPage, "查询成功！");
        } catch (Exception e) {
            log.error(e.getMessage());
            return LayUIPage.failed(e.getMessage());
        }
    }

    /**
     * 用户详情
     *
     * @param id 用户ID
     * @return R<UserInfoVO>
     */
    @SaCheckPermission("nfUser:details")
    @GetMapping("/details")
    @ApiOperation(value = "用户—详情")
    public R<UserInfoVO> getUserInfo(@RequestParam(value = "id") Long id) {
        NfUser nfUser = nfUserService.getById(id);
        return R.ok(nfUserService.getUserInfo(nfUser), "查询成功！");
    }
}

